1
2
3
4 package joeq.ClassLib.Common.java.io;
5
6 import joeq.Class.jq_Array;
7 import joeq.Class.jq_Class;
8 import joeq.Class.jq_Initializer;
9 import joeq.Class.jq_NameAndDesc;
10 import joeq.Class.jq_Type;
11 import joeq.ClassLib.Common.ClassUtils;
12 import joeq.Runtime.Reflection;
13 import joeq.Runtime.Unsafe;
14 import joeq.UTF.Utf8;
15 import jwutil.util.Assert;
16 import jwutil.util.Convert;
17
18 /***
19 * ObjectInputStream
20 *
21 * @author John Whaley <jwhaley@alum.mit.edu>
22 * @version $Id: ObjectInputStream.java 1941 2004-09-30 03:37:06Z joewhaley $
23 */
24 public abstract class ObjectInputStream {
25
26 private static java.lang.ClassLoader latestUserDefinedLoader()
27 throws java.lang.ClassNotFoundException
28 {
29
30 return null;
31 }
32 private static void bytesToFloats(byte[] src, int srcpos, float[] dst, int dstpos, int nfloats) {
33 --dstpos;
34 while (--nfloats >= 0) {
35 dst[++dstpos] = Unsafe.intBitsToFloat(Convert.fourBytesToInt(src, srcpos));
36 srcpos += 4;
37 }
38 }
39 private static void bytesToDoubles(byte[] src, int srcpos, double[] dst, int dstpos, int ndoubles) {
40 --dstpos;
41 while (--ndoubles >= 0) {
42 dst[++dstpos] = Unsafe.longBitsToDouble(Convert.eightBytesToLong(src, srcpos));
43 srcpos += 8;
44 }
45 }
46 private static void setPrimitiveFieldValues(java.lang.Object obj, long[] fieldIDs, char[] typecodes, byte[] data) {
47 Assert.TODO();
48 }
49 private static void setObjectFieldValue(java.lang.Object obj, long fieldID, java.lang.Class type, java.lang.Object val) {
50 Assert.TODO();
51 }
52 private static java.lang.Object allocateNewObject(java.lang.Class aclass, java.lang.Class initclass)
53 throws java.lang.InstantiationException, java.lang.IllegalAccessException
54 {
55 jq_Type t1 = Reflection.getJQType(aclass);
56 if (!(t1 instanceof jq_Class))
57 throw new java.lang.InstantiationException();
58 jq_Type t2 = Reflection.getJQType(initclass);
59 if (!(t2 instanceof jq_Class))
60 throw new java.lang.InstantiationException();
61 jq_Class c1 = (jq_Class)t1;
62 c1.load();
63 if (c1.isAbstract())
64 throw new java.lang.InstantiationException("cannot instantiate abstract "+aclass);
65 jq_Class c2 = (jq_Class)t2;
66 jq_Initializer i = c2.getInitializer(new jq_NameAndDesc(Utf8.get("<init>"), Utf8.get("()V")));
67 if (i == null)
68 throw new InstantiationException("no empty arg initializer in "+initclass);
69 ClassUtils.checkCallerAccess(i, 3);
70 c1.cls_initialize();
71 Object o = c1.newInstance();
72 try {
73 Reflection.invokeinstance_V(i, o);
74 } catch (Error x) {
75 throw x;
76 } catch (java.lang.Throwable x) {
77 throw new ExceptionInInitializerError(x);
78 }
79 return o;
80 }
81 private static java.lang.Object allocateNewArray(java.lang.Class aclass, int length)
82 throws java.lang.NegativeArraySizeException, java.lang.IllegalArgumentException {
83 jq_Type t = Reflection.getJQType(aclass);
84 if (!(t instanceof jq_Array))
85 throw new java.lang.IllegalArgumentException(aclass+" is not an array type");
86 jq_Array a = (jq_Array)t;
87 a.cls_initialize();
88 return a.newInstance(length);
89 }
90
91 }